package org.zzz.controller;

import org.zzz.entity.Attendance;
import org.zzz.entity.AttendanceVo;
import org.zzz.entity.vo.AttendanceShowVo;
import org.zzz.service.AttendanceService;
import org.zzz.service.impl.AttendanceServiceImpl;
import org.zzz.service.impl.UserServiceImpl;
import org.zzz.service.UserService;
import org.zzz.utils.Result;

import java.util.List;

/**
 * @Author ZZF
 * @Time 2021/04/20 22:55
 */
public class AttendanceController {
    private AttendanceService attendanceService = new AttendanceServiceImpl();

    /**
     * 根据课程id选择生成考勤表
     * @param courseId
     * @return
     */
    public Result addAttendanceByCourseId(String date,String status,String courseId,String teacherId){
        return attendanceService.insertBatchAttendanceByClassIdAndCourseId
                (1,courseId,date,status,teacherId,"") == true ?
                Result.success("添加成功") : Result.error("添加失败");
    }

    /**
     * 根据班级和课程id生成考勤表
     * @param classId
     * @return
     */
    public Result addAttendanceByClassAndCourse(String classId,String date,String status,String courseId,String teacherId){
        return attendanceService.insertBatchAttendanceByClassIdAndCourseId
                (0,courseId,date,status,teacherId,classId) == true ?
                Result.success("添加成功") : Result.error("添加失败");
    }

    /**
     * 添加考勤表
     * @param classId
     * @param date
     * @param status
     * @param teacherId
     * @return
     */
    public Result addAttendanceByClass(String sid,
                                       String cid,
                                       String date,
                                       String status,
                                       String teacherId,
                                       String classId){
        return attendanceService.insertAttendanceByClass(sid, cid, date, status, teacherId, classId) == true ? Result.success("添加成功") : Result.error("添加失败");
    }

//    /**
//     * 添加考勤表，有课程
//     * @param classId
//     * @param date
//     * @param status
//     * @param teacherId
//     * @return
//     */
//    public Result addAttendanceByClass(String classId,String date,String courseId,String status,String teacherId){
//        return attendanceService.insertBatchAttendanceByClass(date,status,teacherId,classId) == true ? Result.success("添加成功") : Result.error("添加失败");
//    }

    /**
     * 修改考勤表
     * @param attendance
     * @return
     */
    public Result updateAttendance(Attendance attendance){
        return attendanceService.updateAttendance(attendance) == true ? Result.success("修改成功") : Result.error("修改失败");
    }

    public Result updateAttendanceStatusById(String id,String status){
        return attendanceService.updateAttendanceStatusById(id,status) == true ? Result.success("修改成功") : Result.error("修改失败");
    }

    /**
     * 根据日期显示考勤表
     * @param date
     * @return
     */
    public Result<List<AttendanceVo>> listAttendanceByDate(String date){
        List<AttendanceVo> attendances = attendanceService.listAttendanceByDate(date);
        return !attendances.isEmpty() ? Result.success("查询成功").data(attendances) : Result.error("数据为空");
    }

    public Result<List<AttendanceVo>> listAttendanceByClass(String classId){
        List<AttendanceVo> attendances = attendanceService.listAttendanceByClass(classId);
        return !attendances.isEmpty() ? Result.success("查询成功").data(attendances) : Result.error("数据为空");
    }

    public Result<List<AttendanceVo>> listAttendanceByName(String name){
        List<AttendanceVo> attendances = attendanceService.listAttendanceBySName(name);
        return !attendances.isEmpty() ? Result.success("查询成功").data(attendances) : Result.error("数据为空");
    }

    /**
     * 根据学号获取
     * @param sid
     * @return
     */
    public Result<List<AttendanceShowVo>> listAttendanceBySid(String sid){
        List<AttendanceShowVo> attendances = attendanceService.listAttendanceBySid(sid);
        return !attendances.isEmpty() ? Result.success("查询成功").data(attendances) : Result.error("数据为空");
    }

    /**
     * 根据考勤id获取(修改前的操作)
     * @param id
     * @return
     */
    public Result<AttendanceVo> getAttendanceById(String id){
        AttendanceVo attendance = attendanceService.getAttendanceById(id);
        return attendance!= null ? Result.success("查询成功").data(attendance) : Result.error("查询失败");
    }

    public Result<List<AttendanceShowVo>> listAttendance(String teacherId){
        List<AttendanceShowVo> attendanceVos = attendanceService.listAttendanceVoByTid(teacherId);
        return !attendanceVos.isEmpty() ? Result.success("查询成功").data(attendanceVos) : Result.error("暂无数据");
    }

    public Result<List<AttendanceShowVo>> listAttendanceByDate(String teacherId,String date){
        List<AttendanceShowVo> attendanceVos = attendanceService.listAttendanceVoByTidAndDate(teacherId,date);
        return !attendanceVos.isEmpty() ? Result.success("查询成功").data(attendanceVos) : Result.error("暂无数据");
    }

    /**
     * 根据学生姓名获取考勤信息
     * @param teacherId
     * @param sname
     * @return
     */
    public Result<List<AttendanceShowVo>> listAttendanceBySname(String teacherId,String sname){
        List<AttendanceShowVo> attendanceVos = attendanceService.listAttendanceVoByTidAndSname(teacherId,sname);
        return !attendanceVos.isEmpty() ? Result.success("查询成功").data(attendanceVos) : Result.error("暂无数据");
    }

    /**
     * 根据班级id获取考勤信息
     * @param teacherId
     * @param classId
     * @return
     */
    public Result<List<AttendanceShowVo>> listAttendanceByClassId(String teacherId,String classId){
        List<AttendanceShowVo> attendanceVos = attendanceService.listAttendanceVoByTidAndClassId(teacherId,classId);
        return !attendanceVos.isEmpty() ? Result.success("查询成功").data(attendanceVos) : Result.error("暂无数据");
    }
}
